home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / gs3.53 / pfbtogs.ps < prev    next >
Text File  |  1996-01-10  |  4KB  |  114 lines

  1. %    Copyright (C) 1991, 1992, 1994 Aladdin Enterprises.  All rights reserved.
  2. %
  3. % This file is part of Ghostscript.
  4. %
  5. % Ghostscript is distributed in the hope that it will be useful, but
  6. % WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. % to anyone for the consequences of using it or for whether it serves any
  8. % particular purpose or works at all, unless he says so in writing.  Refer
  9. % to the Ghostscript General Public License for full details.
  10. %
  11. % Everyone is granted permission to copy, modify and redistribute
  12. % Ghostscript, but only under the conditions described in the Ghostscript
  13. % General Public License.  A copy of this license is supposed to have been
  14. % given to you along with Ghostscript so you can know your rights and
  15. % responsibilities.  It should be in a file named COPYING.  Among other
  16. % things, the copyright notice and this notice must be preserved on all
  17. % copies.
  18.  
  19. % pfbtogs.ps
  20. % Convert a PFB file to a Ghostscript font.
  21.  
  22. % A .pfb file is a sequence of packets.  Each packet starts with byte
  23. % 0x80.  The second byte in the packet gives the type of packet: 1
  24. % means it's a packet of ascii data which should be sent out as is
  25. % (except for translating \r to the appropriate end-of-line
  26. % character(s)); 2 means it's a packet of binary data (which may be
  27. % translated into hex); 3 means EOF.  For types 1 and 2, the type byte
  28. % is followed by four bytes giving the length of the packet, least
  29. % significant first.
  30.  
  31. /envPFB 20 dict def
  32. envPFB begin
  33.  
  34. % ------ Packet writing routines ------ %
  35.  
  36.    /pfbtext        % str ->
  37.      {  { (\r) search
  38.            { ofile exch writestring pop
  39.          ofile (\n) writestring
  40.        }
  41.        { ofile exch writestring exit
  42.        }
  43.       ifelse
  44.     } loop
  45.      } def
  46.  
  47.    /pfbbinary        % str ->
  48.     {  { dup length 30 gt
  49.           { dup 0 30 getinterval ofile exch writehexstring
  50.         ofile (\n) writestring
  51.         dup length 30 sub 30 exch getinterval
  52.       }
  53.       { ofile exch writehexstring exit
  54.       }
  55.      ifelse
  56.        } loop ofile (\n) writestring
  57.      } def
  58.  
  59.    /pfbcopy        % count proc ->
  60.     { exch        % proc count
  61.        { dup bufsize min
  62.          buf 0 3 -1 roll getinterval
  63.      2 index exec
  64.      bufsize sub dup 0 le { exit } if
  65.        } loop pop pop
  66.     } def
  67.  
  68. % ------ The main program ------ %
  69.  
  70.    /bufsize 30000 def
  71.    /buf bufsize string def
  72.  
  73.    /pfbtogs        % infilename outfilename pfbtogs ->
  74.     { /psname exch def
  75.       /pfbname exch def
  76.  
  77.       pfbname (r) file /ifile exch def
  78.       /packet 6 string def
  79.       ifile packet readstring
  80.        { dup length 6 eq { 0 get 128 eq } { pop false } ifelse }
  81.        { pop false }
  82.       ifelse
  83.       not { (Not a valid .PFB file.\n) print flush stop } if
  84.  
  85.       ifile 0 setfileposition
  86.       psname (w) file /ofile exch def
  87.  
  88.        { ifile packet readstring
  89.          not { exit } if
  90.      (packet: ) print packet { ( ) print =only } forall (\n) print flush
  91.      packet 5 get 256 mul packet 4 get add
  92.      256 mul packet 3 get add 256 mul packet 2 get add
  93.      packet 1 get 1 sub
  94.       { { { ifile exch readstring pop pfbtext } pfbcopy }
  95.         { { ifile exch readstring pop pfbbinary } pfbcopy }
  96.         { exit }
  97.       } exch get exec
  98.        } loop
  99.  
  100.       ofile closefile
  101.       ifile closefile
  102.  
  103.     } bind def
  104.  
  105. end
  106.  
  107. % Enter the main program in the current dictionary.
  108. /pfbtogs
  109.  { envPFB begin   pfbtogs end
  110.  } bind def
  111.  
  112. % If the program was invoked from the command line, run it now.
  113. shellarguments { pfbtogs } if
  114.